import http from '@/tool/http'
import axios from 'axios'
import url from '@/tool/api'
const state = {
	tableData:[],
	dataCount:0,
	seach:{}
}
const mutations = {
	setData(state,arr){
		state.tableData = []
		if(arr instanceof Array){
			state.tableData = arr
		}else{
			state.tableData.push(arr)
		}
		
	},
	setCount(state,num){
		state.dataCount = num
	},
	setSeach(state){
		state.seach = {}
	}
}
const actions = {
	actGetJobData({commit},num){
		// console.log(num)
		let obj = state.seach
		if(num===undefined){
			num = 0
		}else{
			num = (num-1)*5
		}
		return new Promise((resolve,reject)=>{
			http({
				url:url.getjobCount,
				method:'post'
			}).then(res=>{
				// console.log(res)
				if(res.data.code==='200'){
					commit('setCount',res.data.count)
					resolve(res.data.count)
				}
			})
		}).then(res=>{
			http({
				url:url.getjobData,
				method:'post',
				data:{
					num1:num,
					num2:5,
					reqData:obj
				}
			}).then(res=>{
				// console.log(res)
				commit('setData',res.data.data)
				commit('setSeach')
				return res.data.code
			})
		})
	},
	delJob({commit},name){
		// console.log(name)
		return http({
			url:url.deljob,
			method:'post',
			data:{
				name:name
			}
		}).then(res=>{
			console.log(res)
			return res.data.code
		})
	},
	editJob({commit},obj){
		console.log(obj)
		return http({
			url:url.editjob,
			method:'post',
			data:obj
		}).then(res=>{
			console.log(res)
			return res.data.code
		})
	},
	addJob({commit},obj){
		console.log(obj)
		return http({
			url:url.addjob,
			method:'post',
			date:obj
		}).then(res=>{
			console.log(res)
		})
	}
}
const getters = {
	
}

export default {
	state,mutations,actions,getters
}